{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "94a4af82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/50\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\anaconda\\lib\\site-packages\\sklearn\\utils\\extmath.py:1047: RuntimeWarning: invalid value encountered in divide\n",
      "  updated_mean = (last_sum + new_sum) / updated_sample_count\n",
      "D:\\anaconda\\lib\\site-packages\\sklearn\\utils\\extmath.py:1052: RuntimeWarning: invalid value encountered in divide\n",
      "  T = new_sum / new_sample_count\n",
      "D:\\anaconda\\lib\\site-packages\\sklearn\\utils\\extmath.py:1072: RuntimeWarning: invalid value encountered in divide\n",
      "  new_unnormalized_variance -= correction**2 / new_sample_count\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18/18 [==============================] - 1s 11ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 2/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 3/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 4/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 5/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 6/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 7/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 8/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 9/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 10/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 11/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 12/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 13/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 14/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 15/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 16/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 17/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 18/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 19/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 20/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 21/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 22/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 23/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 24/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 25/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 26/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 27/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 28/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 29/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 30/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 31/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 32/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 33/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 34/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 35/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 36/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 37/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 38/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 39/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 40/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 41/50\n",
      "18/18 [==============================] - 0s 2ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 42/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 43/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 44/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 45/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 46/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 47/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 48/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 49/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "Epoch 50/50\n",
      "18/18 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.6074 - val_loss: nan - val_accuracy: 0.6643\n",
      "6/6 [==============================] - 0s 974us/step\n",
      "Test Accuracy: 0.6123595505617978\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "Per-column arrays must each be 1-dimensional",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[30], line 69\u001b[0m\n\u001b[0;32m     66\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTest Accuracy:\u001b[39m\u001b[38;5;124m\"\u001b[39m, accuracy)\n\u001b[0;32m     68\u001b[0m \u001b[38;5;66;03m# 生成提交文件\u001b[39;00m\n\u001b[1;32m---> 69\u001b[0m submission \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mDataFrame\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mPassengerId\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtest_data\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mPassengerId\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mSurvived\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mpredictions\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     70\u001b[0m submission\u001b[38;5;241m.\u001b[39mto_csv(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msubmission.csv\u001b[39m\u001b[38;5;124m'\u001b[39m, index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
      "File \u001b[1;32mD:\\anaconda\\lib\\site-packages\\pandas\\core\\frame.py:664\u001b[0m, in \u001b[0;36mDataFrame.__init__\u001b[1;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[0;32m    658\u001b[0m     mgr \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_init_mgr(\n\u001b[0;32m    659\u001b[0m         data, axes\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mindex\u001b[39m\u001b[38;5;124m\"\u001b[39m: index, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcolumns\u001b[39m\u001b[38;5;124m\"\u001b[39m: columns}, dtype\u001b[38;5;241m=\u001b[39mdtype, copy\u001b[38;5;241m=\u001b[39mcopy\n\u001b[0;32m    660\u001b[0m     )\n\u001b[0;32m    662\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(data, \u001b[38;5;28mdict\u001b[39m):\n\u001b[0;32m    663\u001b[0m     \u001b[38;5;66;03m# GH#38939 de facto copy defaults to False only in non-dict cases\u001b[39;00m\n\u001b[1;32m--> 664\u001b[0m     mgr \u001b[38;5;241m=\u001b[39m \u001b[43mdict_to_mgr\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindex\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcopy\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcopy\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtyp\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmanager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    665\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(data, ma\u001b[38;5;241m.\u001b[39mMaskedArray):\n\u001b[0;32m    666\u001b[0m     \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mma\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmrecords\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mmrecords\u001b[39;00m\n",
      "File \u001b[1;32mD:\\anaconda\\lib\\site-packages\\pandas\\core\\internals\\construction.py:493\u001b[0m, in \u001b[0;36mdict_to_mgr\u001b[1;34m(data, index, columns, dtype, typ, copy)\u001b[0m\n\u001b[0;32m    489\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    490\u001b[0m         \u001b[38;5;66;03m# dtype check to exclude e.g. range objects, scalars\u001b[39;00m\n\u001b[0;32m    491\u001b[0m         arrays \u001b[38;5;241m=\u001b[39m [x\u001b[38;5;241m.\u001b[39mcopy() \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(x, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdtype\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m x \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m arrays]\n\u001b[1;32m--> 493\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43marrays_to_mgr\u001b[49m\u001b[43m(\u001b[49m\u001b[43marrays\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindex\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtyp\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtyp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconsolidate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcopy\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\anaconda\\lib\\site-packages\\pandas\\core\\internals\\construction.py:118\u001b[0m, in \u001b[0;36marrays_to_mgr\u001b[1;34m(arrays, columns, index, dtype, verify_integrity, typ, consolidate)\u001b[0m\n\u001b[0;32m    115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m verify_integrity:\n\u001b[0;32m    116\u001b[0m     \u001b[38;5;66;03m# figure out the index, if necessary\u001b[39;00m\n\u001b[0;32m    117\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m index \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 118\u001b[0m         index \u001b[38;5;241m=\u001b[39m \u001b[43m_extract_index\u001b[49m\u001b[43m(\u001b[49m\u001b[43marrays\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    119\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    120\u001b[0m         index \u001b[38;5;241m=\u001b[39m ensure_index(index)\n",
      "File \u001b[1;32mD:\\anaconda\\lib\\site-packages\\pandas\\core\\internals\\construction.py:653\u001b[0m, in \u001b[0;36m_extract_index\u001b[1;34m(data)\u001b[0m\n\u001b[0;32m    651\u001b[0m         raw_lengths\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mlen\u001b[39m(val))\n\u001b[0;32m    652\u001b[0m     \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(val, np\u001b[38;5;241m.\u001b[39mndarray) \u001b[38;5;129;01mand\u001b[39;00m val\u001b[38;5;241m.\u001b[39mndim \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m--> 653\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPer-column arrays must each be 1-dimensional\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m    655\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m indexes \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m raw_lengths:\n\u001b[0;32m    656\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIf using all scalar values, you must pass an index\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mValueError\u001b[0m: Per-column arrays must each be 1-dimensional"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import tensorflow as tf\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "# 读取数据集\n",
    "data = pd.read_csv('train.csv')\n",
    "test_data = pd.read_csv('test.csv')\n",
    "\n",
    "# 数据预处理\n",
    "def process(data):\n",
    "    data['Sex'] = data['Sex'].map({'male': 0, 'female': 1})  # 将性别转换为数值\n",
    "    # 删除缺省值记录不是一个好的选择！\n",
    "    data.dropna(subset=['Embarked'],inplace=True)  # 删除登船港口的缺失值\n",
    "\n",
    "    # fill_values = {'Age': 0}\n",
    "    # data = data.fillna(fill_values)\n",
    "    average = data['Age'].mean()\n",
    "    data['Age'].fillna(average,inplace=True)\n",
    "    # print(\"average:\",average)\n",
    "    # data['Age'] = data['Age'].apply(lambda x: x if x > 0 else average) # 将年龄缺失的记录设置为平均年龄\n",
    "\n",
    "    data['Cabin'] = data['Cabin'].notnull().astype(int) # 将cabin列中有值的设置为1，没值的设置为0\n",
    "    # print(data.head(10))\n",
    "    return data\n",
    "\n",
    "data = process(data)\n",
    "test_data = process(data)\n",
    "\n",
    "features = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare','Cabin']\n",
    "X = data[features]\n",
    "y = data['Survived']\n",
    "\n",
    "# 特征缩放\n",
    "scaler = StandardScaler()\n",
    "X_scaled = scaler.fit_transform(X)\n",
    "\n",
    "# 划分训练集和测试集\n",
    "X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)\n",
    "\n",
    "# 构建神经网络模型\n",
    "model = tf.keras.Sequential([\n",
    "    tf.keras.layers.Dense(64, activation='relu', input_shape=(X_train.shape[1],)),\n",
    "    tf.keras.layers.BatchNormalization(),\n",
    "    tf.keras.layers.Dropout(0.2),\n",
    "    tf.keras.layers.Dense(32, activation='relu'),\n",
    "    tf.keras.layers.BatchNormalization(),\n",
    "    tf.keras.layers.Dropout(0.2),\n",
    "    tf.keras.layers.Dense(1, activation='sigmoid')\n",
    "])\n",
    "\n",
    "# 编译模型\n",
    "model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])\n",
    "\n",
    "# 训练模型\n",
    "model.fit(X_train, y_train, epochs=50, batch_size=32, validation_split=0.2)\n",
    "\n",
    "# 模型预测\n",
    "y_pred = model.predict(X_test)\n",
    "y_pred_binary = (y_pred > 0.5).astype(int)\n",
    "\n",
    "# 计算准确率\n",
    "accuracy = accuracy_score(y_test, y_pred_binary)\n",
    "print(\"Test Accuracy:\", accuracy)\n",
    "\n",
    "# 生成提交文件\n",
    "submission = pd.DataFrame({'PassengerId': test_data['PassengerId'], 'Survived': predictions})\n",
    "submission.to_csv('submission.csv', index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
